package com.briup.jz.web.controller;

import com.briup.jz.bean.AccountSystem;
import com.briup.jz.bean.extend.AccountSystemExtend;
import com.briup.jz.service.IAccountSystemService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: jz
 * @description: 账户系统控制器
 * @author: catmilko
 * @create: 2020/6/12 15:52
 **/
@RestController
@RequestMapping("/AccountSystemController")
@Api(description = "系统账户管理接口")
public class AccountSystemController {
    @Autowired
    private IAccountSystemService accountSystemService;

    @ApiOperation(value = "查询所有系统账户信息")
    @GetMapping("findAll")
    public Message findAll() {
        List<AccountSystem> list = accountSystemService.findAll();
        return MessageUtil.success(list);
    }


    @ApiOperation(value = "通过id查询系统账户信息")
    @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    @GetMapping("findById")
    public Message findById(long id) {
        AccountSystem accountSystem = accountSystemService.findById(id);
        return MessageUtil.success(accountSystem);
    }

    @ApiOperation(value = "保存或通过id更新系统账户信息")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(AccountSystem accountSystem) {
        accountSystemService.saveOrUpdate(accountSystem);
        return MessageUtil.success("保存成功");
    }

    @ApiOperation(value = "通过id删除系统账户信息")
    @ApiImplicitParam(name = "id", value = "类别唯一编号", required = true, paramType = "query")
    @GetMapping("deleteById")
    public Message deleteById(long id) {
        accountSystemService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "查询系统账户+订单+用户信息")
    @GetMapping("findAllWithOrderAndUser")
    public Message findAllWithOrderAndUser() {
        List<AccountSystemExtend> list = accountSystemService.findAllWithOrderAndUser();
        return MessageUtil.success(list);
    }
}
